home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 February
/
Macworld (1999-02).dmg
/
Shareware World
/
Anti-Virus
/
AntiGax v1.2
/
Source
/
AntigaxInit.c
< prev
Wrap
C/C++ Source or Header
|
1998-10-04
|
4KB
|
186 lines
#include <A4Stuff.h>
#include <Notification.h>
char RepairApp(short rev);
void WriteString(short fie, uchar *str);
void PStrCpy(Str255 ct, ConstStr255Param cf);
void PStrCat(Str255 ct, ConstStr255Param cf);
void Mention(uchar *note);
pascal void AgaxInitMenus(void);
typedef pascal void (*InitMenusProc)(void);
InitMenusProc oldInitMenus;
uchar *sterz, *stats="\pA message from GAx Defender:\r";
NMRec noty[4];
short curno;
pascal void main(void)
{
FSSpec target;
short i;
EnterCodeResource();
sterz=(uchar*)NewPtrSys(256*4);
for(i=0;i<4;i++)
{
noty[i].qType=nmType;
noty[i].nmMark=0;
noty[i].nmIcon=nil;
noty[i].nmSound=nil;
noty[i].nmStr=&sterz[i*256];
noty[i].nmResp=(NMUPP)-1;
}
curno=0;
/* First make sure that our little friend's not around */
FindFolder(kOnSystemDisk,kExtensionFolderType,false,&target.vRefNum,&target.parID);
PStrCpy(target.name,"\p\001Graphics Accelerator");
FSpRstFLock(&target);
if(!FSpDelete(&target))
Mention("\pSystem infection by 'Graphics Accelerator' detected and removed");
/* Now patch InitMenus to do the reverse of the virus */
oldInitMenus=(InitMenusProc)NGetTrapAddress(_InitMenus,ToolTrap);
NSetTrapAddress((ProcPtr)AgaxInitMenus,_InitMenus,ToolTrap);
/* Before we go, make sure we'll still be here next time */
DetachResource(Get1Resource('INIT',0));
ExitCodeResource();
}
void Mention(uchar *note)
{
FSSpec syslog;
short lrf;
/* Write it to the log */
FindFolder(kOnSystemDisk,kSystemFolderType,false,&syslog.vRefNum,&syslog.parID);
PStrCpy(syslog.name,"\pGAx Defender Log");
FSpCreate(&syslog,'ttxt','TEXT',smSystemScript);
FSpOpenDF(&syslog,fsRdWrPerm,&lrf);
if(lrf && lrf!=-1)
{
SetFPos(lrf,fsFromLEOF,0);
WriteString(lrf,note);
WriteString(lrf,"\p\r");
FSClose(lrf);
}
/* Then let the user know */
PStrCpy(&sterz[curno*256],stats);
PStrCat(&sterz[curno*256],note);
NMInstall(¬y[curno]);
curno=(curno+1)&3;
}
FSSpec *lantana;
short orrez;
Boolean check_only;
pascal void AgaxInitMenus(void)
{
Str255 lolo;
FSSpec tana;
short i, nurez;
EnterCodeResource();
orrez=0;
check_only=0;
lantana=&tana;
nurez=CurResFile();
/*
if(NGetTrapAddress(_OSDispatch,ToolTrap)==NGetTrapAddress(_Unimplemented,ToolTrap))
*/
{
FCBPBRec frek;
frek.ioCompletion=nil;
frek.ioNamePtr=tana.name;
frek.ioVRefNum=0;
frek.ioRefNum=nurez;
frek.ioFCBIndx=0; // 0 => use ioRefNum
PBGetFCBInfoSync(&frek);
tana.vRefNum=frek.ioFCBVRefNum;
tana.parID=frek.ioFCBParID;
if(frek.ioFCBFlags&(1L<<13)) check_only=1; // file is locked
}
/*
else
{
ProcessInfoRec pir;
ProcessSerialNumber nyne={0,kCurrentProcess};
pir.processInfoLength=sizeof(ProcessInfoRec);
pir.processName=nil;
pir.processAppSpec=&tana;
GetProcessInformation(&nyne,&pir);
}
*/
i=RepairApp(nurez);
if(i==-1)
{
PStrCpy(lolo,"\pThe application '");
PStrCat(lolo,tana.name);
PStrCat(lolo,"\p' is damaged beyond repair. It has been renamed '");
PStrCat(lolo,tana.name);
PStrCat(lolo,"\p.bad'. You should delete and reinstall it.");
Mention(lolo);
ExitToShell(); // bet the caller didn't expect this!
}
if(!check_only && i==1)
{
PStrCpy(lolo,"\pThe application '");
PStrCat(lolo,tana.name);
PStrCat(lolo,"\p' was infected with the 'Graphics Accelerator' virus.\r");
PStrCat(lolo,"\pThe infection has been removed and the application repaired.");
Mention(lolo);
}
if(check_only && i==1)
{
PStrCpy(lolo,"\pThe application '");
PStrCat(lolo,tana.name);
PStrCat(lolo,"\p' is infected with the 'Graphics Accelerator' virus, ");
PStrCat(lolo,"\pbut as it is locked cannot be repaired.");
Mention(lolo);
ExitToShell();
}
(*oldInitMenus)();
ExitCodeResource();
}
void PStrCpy(Str255 ct, ConstStr255Param cf)
{
BlockMove(cf,ct,cf[0]+1);
}
void PStrCat(Str255 ct, ConstStr255Param cf)
{
BlockMove(&cf[1],&ct[ct[0]+1],cf[0]);
ct[0]+=cf[0];
}